package com.qxsx.midi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.model.Apply;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Joney on 2015/9/9.
 */
public class ApplyAdapter extends BaseAdapter {

    private Context context;

    private List<Apply> lists;

    public ApplyAdapter(Context context, List<Apply> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void AddData(List<Apply> list) {
        for (Apply apply : list) {
            lists.add(apply);
        }
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.me_apply_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_desc = (TextView) convertView.findViewById(R.id.tv_desc);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        return convertView;
    }

    static class ViewHolder {
        private ImageView iv_img;
        private TextView tv_title;
        private TextView tv_desc;

    }
}
